<template>
  <el-dialog
    append-to-body
    title="地址选择"
    :visible.sync="dialogVisible"
    :close-on-click-modal="false"
    align="left"
    v-loading="currLoading"
    element-loading-text="拼命加载中"
    element-loading-spinner="el-icon-loading"
    element-loading-background="rgba(0, 0, 0, 0.8)"
    width="550px">
    <div v-if="dialogVisible">
      <address-item v-for="(address,index) in addressList" :address-data="address" :key="index" :show-type="2" :choose-address-call-back="chooseAddress"/>
    </div>
  </el-dialog>
</template>

<script>
import AddressItem from '../Common/AddressItem'
export default {
  name: 'ChooseAddressDialog',
  components: {AddressItem},
  data: function () {
    return {
      dialogVisible: false,
      currLoading: false,
      addressList:[],
      callback:null
    }
  },
  mounted () {
    let $this=this
    this.bus.$on('ChooseAddressDialogCallBus',function (callback) {
      $this.dialogVisible=true
      $this.callback=callback
      $this.getAddressList()
      $this.$forceUpdate()
    })
  },
  methods: {
    chooseAddress:function (address) {
      if (typeof this.callback==='function'){
        this.callback(address)
        this.dialogVisible=false
        this.$forceUpdate()
      }
    },
    open: function () {
      this.dialogVisible = true
      this.getAddressList()
      this.$forceUpdate()
    },
    getAddressList:function () {
      let $this=this
      $this.MyRequest(this.ApiDoNameSupplier+"SupplierAddress/getList",{},function (addressList) {
        $this.addressList=addressList
        $this.$forceUpdate()
      })
    }
  }
}
</script>

<style scoped>

</style>
